/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef TRI_PARTICLE_ENGINE_H_
#define TRI_PARTICLE_ENGINE_H_

#include <GL/gl.h>
#include <GL/glu.h>

#include "camera.h"
#include "glyph.h"
#include "graphics.h"
#include "base/vector.h"

namespace tri{

class TParticle : public tri::TGlyph{
public:
	TParticle();
	virtual ~TParticle();
	
	virtual void display();
	virtual void update();
	void setActive(bool b);
	bool isActive();
	void setLifeSpan(float l);
	void setVelocity(TVector vel);
	void setGravity(TVector grav);
	
private:
	bool m_Active;
	tri::TVector m_Gravity;
	tri::TVector m_Velocity;
	float m_LifeSpan;
	float elapsedTime;
	TProgressTimer m_Timer;
};


class TParticleEngine : public tri::TEntity{
public:
	TParticleEngine();
	virtual ~TParticleEngine();
	
	void display();
	void reset();
	void setParticleCount(unsigned int size);
	virtual void update();
	void setParticleVelocity(TVector v);
	void setParticleVelocity(TVector min,TVector max);
	void setParticleGravity(TVector g);
	void setParticleColor(graphics::TColor c);
	void setParticleColor(graphics::TColor s, graphics::TColor e);
	void setParticlePosition(TVector p);
	void setParticlePosition(TVector min, TVector max);
	void setParticleLifeSpan(float ls);
	void setParticleLifeSpan(float min, float max);
	void setParticleImage(std::string image);
	void setParticleSize(float s);
private:

	void resetParticle(TParticle* p);

	std::vector<TParticle> m_Pool;
	
	unsigned int m_PoolSize;
	
	
	graphics::TColor m_StartColor;
	graphics::TColor m_EndColor;
	
	TVector m_MinOrigPosition;
	TVector m_MaxOrigPosition;
	
	TVector m_MinVelocity;
	TVector m_MaxVelocity;
	
	TVector m_Gravity;
	
	float m_MinLifeSpan;
	float m_MaxLifeSpan;
	
	std::string mParticleImage;
	
	float m_ParticleSize;

};

}
#endif /*DISPLAY_ENGINE_H_*/
